const { spawn } = require('node:child_process')

const commandSpawn = function (...args) {
  return new Promise((resolve, reject) => {
    // spawn执行后会返回一个子进程
    const childProcess = spawn(...args)
    // 将子进程的输出流放在主进程中
    childProcess.stdout.pipe(process.stdout)
    childProcess.stderr.pipe(process.stderr)
    // 监听子进程结束
    childProcess.on('close', () => {
      resolve()
    })
  })
}
module.exports = {
  commandSpawn
}